<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function getObjectPath(obj, window=global) {
  let pathes = [];
  (function findPath(currentObj, parentObj, currentPath) {
    for (let key in parentObj) {
      if (parentObj.hasOwnProperty(key)) {
        if (parentObj[key] === currentObj) {
          pathes.push(currentPath + key);
        } else if (typeof parentObj[key] === 'object' && parentObj[key] !== null) {
          findPath(currentObj, parentObj[key], currentPath + key + '.');
        }
      }
    }
  })(obj, window, '');
  return pathes.length > 0 ? pathes[0] : null;
}
 
// 示例使用：
const myObject  = {
            user: "henq",
            live: ["台球", "自行车", "旅行"],
            list: [{ name: "汽车", id: 1 }, { name: "卡尺", id: 2 }, { name: "吉祥", id: 3 }],
        }
window.myRef = myObject;
console.log(getObjectPath(myObject.live[0])); // 输出: "myRef"
    </script>
</body>
</html>